package com.godofgamblers.hotelmanagementsystem.service.imp;

import com.godofgamblers.hotelmanagementsystem.mapper.WorkingMapper;
import com.godofgamblers.hotelmanagementsystem.pojo.User;
import com.godofgamblers.hotelmanagementsystem.pojo.Worker;
import com.godofgamblers.hotelmanagementsystem.service.WorkingService;
import lombok.Data;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/*

@author huanglang

@create_time 2019-10-22 19:59

Nothing is difficult but bugs

*/
@Service
@Data
public class WorkingServiceImp implements WorkingService {

    @Autowired
    private WorkingMapper workingMapper;

    @Override
    public void checkWork(User user) {
        //向订单表中插入数据
        Date date = new Date();
        String work_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);   //获取创建订单时候的时间
        Map<String, Object> map = new HashedMap();
        map.put("user_id", user.getUser_id());
        map.put("work_time", work_time);
        workingMapper.setTodayWorker(map);
    }

    @Override
    public Worker checkTodayWorker() {
        Date date = new Date();
        String work_time = new SimpleDateFormat("yyyy-MM-dd").format(date);
        work_time = work_time + "%";
        return workingMapper.getTodayWorker(work_time);
    }

    @Override
    public void checkOffWork(User user) {
        //向订单表中插入数据
        Date date = new Date();
        String off_work_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);   //获取创建订单时候的时间
        Map<String, Object> map = new HashedMap();
        map.put("user_id", user.getUser_id());
        map.put("off_work_time", off_work_time);
        workingMapper.setTodayWorkerOff(map);
    }
}
